[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 ungetch()               Push Back the Last Character Read from the Console

 #include   <conio.h>                    Required for declarations only

 int        ungetch(c);
 int        c;                           Character to be pushed

    ungetch() pushes back 'c', the last character read from the console.
    'c' will then be the next character read.  ungetch() can only be
    called once between read() statements.

       Returns:     The character 'c', if successful.  A return value of
                    EOF indicates an error.

   Portability:     MS-DOS only.

   -------------------------------- Example ---------------------------------

    The following statements get digits and alphabetic characters from
    the console.

           #include <conio.h>
           #include <ctype.h>

           char item[80];
           char qty[5];
           int x, y;
           char ch;

           main()
           {
               while (isdigit(ch = getche()))
                     qty[y++] = ch;
               /* process 'qty' */
               if (isalpha(ch))
                  ungetch(ch);
               while (isalpha(ch = getche()))
                     item[x++] = toupper(ch);
               /* process 'item' */
               printf("\n%s %s\n",qty,item);
           }


See Also: ungetc() cscanf() getch() getche()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson